public class Test20 {
    public int maxSubarraySumCircular(int[] nums) {
        int n = nums.length;
        int[] f = new int[n + 1];
        int[] g = new int[n + 1];
        int maxNum = 0;
        int minNum = 0;
        int sum = 0;
        for(int i = 1;i <= n;i++) {
            f[i] = Math.max(f[i - 1] + nums[i - 1],nums[i - 1]);
            g[i] = Math.min(g[i - 1] + nums[i - 1],nums[i - 1]);
            maxNum = Math.max(f[i],maxNum);
            minNum = Math.min(g[i],minNum);
            sum += nums[i - 1];
        }
        System.out.println(maxNum);
        System.out.println(minNum);
        if (sum - minNum == 0) {
            return maxNum;
        }
        return Math.max(maxNum,sum - minNum);
    }

    public static void main(String[] args) {
        Test20 test20 = new Test20();
        int[] arr = {-3,-2,-3};
        test20.maxSubarraySumCircular(arr);
    }
}
